﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Show Product
</asp:Content>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        ListView1.DataSource = ViewData.Model;
        ListView1.DataBind(); 
    }
    protected string writeAddToCart(object amount, object id)
    {
        string a;
        if (int.Parse(amount.ToString()) > 0)
            a = "<a href='/Cart/AddCart/" + id.ToString() + "'><img width='80' height='30' alt='' src='../../Content/images/buynow.png' /></a>";
        else
            a = "<img src='../../Content/images/blank.png' border='0' />";
        
        return a;
    }
    protected string writeSoldOut(object amount)
    {
        string a = "";
        if (int.Parse(amount.ToString()) < 1)
            a = "<i style='margin-left:2px; background-image: url(../../Content/images/sold_out.png); width:190px; height:108px; position: absolute;'> </i>";

        return a;
    }
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <h2><%=Html.Encode(ViewData["title"])%></h2>
    <table align="left" cellpadding="0" cellspacing="0" 
        style="width: 100%; float: left">
        <tr>
            <td>
            <asp:ListView ID="ListView1" runat="server">
                <ItemTemplate>
                    <div class="product_box">
                        <h3><%#Eval("TenSanPham")%></h3>
                        <div class="image_wrapper">
                            <a href="/Product/Detail/<%#Eval("MaSanPham")%>">
                                <%#writeSoldOut(Eval("SL_Ton"))%>
                                <img src="<%#Eval("Hinh") %>" alt="" width="190px" height="108px" />
                            </a>
                        </div> 
                        <p class="price">Price: <%#Eval("Gia")%></p>
                        <center><%#writeAddToCart(Eval("SL_Ton"), Eval("MaSanPham"))%></center>
                    </div>        
                </ItemTemplate> 
            </asp:ListView>
            </td>
        </tr>
        <tr>
            <td>
    <center><asp:DataPager ID="DataPager1" PageSize="6" QueryStringField="Page" PagedControlID="ListView1" runat="server">
        <Fields>
            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                ShowNextPageButton="False" ShowPreviousPageButton="False" />
            <asp:NumericPagerField />
            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 
                ShowNextPageButton="False" ShowPreviousPageButton="False" />
        </Fields>
    </asp:DataPager></center>
            </td>
        </tr>
    </table>
</asp:Content>
